<template>
  <div>
    <Title :title="title"></Title>
    <div class="content">
      <h3>数据权限</h3>
      <el-radio-group v-model="radio" style="margin-top: 20px;">
        <el-radio label="0" border>个人级</el-radio>
        <el-radio label="1" border>部门级</el-radio>
        <el-radio label="2" border>公司级</el-radio>
      </el-radio-group>

      <div style="background: #fff; text-align: right; margin-top:50px;">
        <el-button type="info" @click="cancel"> 取消 </el-button>
        <el-button type="primary" @click="addPermission"> 确定 </el-button>
      </div>
      <!-- <el-col :span="6" v-for="item in resourceTree" :key="item.code">
        <el-checkbox
          :label="item.code"
          :true-label="item.code"
          @change="changeCheck"
          >{{ item.title }}</el-checkbox
        >
      </el-col>  -->
    </div>
  </div>
</template>
<script>
import Title from '@/components/header.vue'

import {
  getResource,
  setResource,
} from '@/api/permission'
import myTrees from './tree/treeMenus'
export default {
  components: {
    myTrees,
    Title,
  },
  data() {
    return {
      title: '权限设置',
      positionId: '',
      dataPermission: [],
      resourceTree: [],
      dataPer: '',
      checked: '',
      radio: null,
    }
  },
  created() {
    this.positionId = this.$route.query.id
    this.getResourceTree()
  },
  methods: {
    cancel() {
      this.$router.go(-1)
    },
    async addPermission() {
      const res = await setResource(this.positionId, Number(this.radio))
      if (res.code == 200) {
        this.$message({
          type: 'success',
          message: '保存成功',
        })
        this.$router.push('/permission/job')
      }
      // const res = await saveResource(this.resourceTree)
      // if (res.code == 200) {
      //   this.$message({
      //     type: 'success',
      //     message: '保存成功',
      //   })
      //   this.$router.push('/permission/job')
      // }
      // console.log('res', res)
    },
    // async changeCheck(val) {
    //   this.resourceTree.forEach((item) => {
    //     if (item.code == val) {
    //       item.isSelected = true
    //     }
    //   })
    // },
    async getResourceTree() {
      const res = await getResource(this.positionId)
      if (res.code == 200) {
        this.radio = String(res.data)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.content {
  width: 90%;
  height: 620px;
  background: #fff;
  padding-bottom: 50px;
  padding: 50px;
}
</style>
